import api from '@/libs/request'
import { Page } from '@/components/pageManage'
import { ChatMessage } from '@/basePackage/pages/customerService/types'

/**
 * 分页查询当前店铺通知
 */
export const messagePage = (params: any) => {
  return api.get('/gruul-mall-carrier-pigeon/pigeon/notice', params)
}

/**
 * 根据id获取消息详情
 */
export const getMessageById = (messageId: string) => {
  return api.get(`/gruul-mall-carrier-pigeon/pigeon/notice/${messageId}`)
}

/**
 * 分页查询用户列表
 */
export const getMessageUsers = (keywords: string, page: Page) => {
  return api.get(`gruul-mall-carrier-pigeon/pigeon/message/user`, { ...page, keywords })
}

/**
 * 分页查询用户聊天记录
 */
export const getMessages = (userId: string, page: Page) => {
  return api.get(`/gruul-mall-carrier-pigeon/pigeon/message/user/${userId}/message`, page)
}

/**
 * 发送消息给用户
 * @param userId 用户id
 * @param data 消息体
 */
export const sendMessages = (userId: string, data: ChatMessage) => {
  return api.post(`/gruul-mall-carrier-pigeon/pigeon/message/user/${userId}/message`, data)
}
/**
 * 用户消息设置为已读
 */
export const readMessages = (userId: string, messageIds: string[]) => {
  return api.put(`/gruul-mall-carrier-pigeon/pigeon/message/user/${userId}/read`, messageIds)
}

/**
 * 获取订阅模板
 */
export const getTemplateIds = () => {
  return api.get(`gruul-mall-carrier-pigeon/appletMessageSubscribe/getTemplateIds`)
}
